﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <html>

    <head>
      <link rel="stylesheet" href="${ctx}/common/common.css" />
      <title>Title</title>
      <link href="${ctx}/common/plugins/tableTree/layui/css/layui.css" rel="stylesheet" />
      <script src="${ctx}/common/plugins/tableTree/jquery-1.10.2.min.js"></script>
      <script src="${ctx}/common/plugins/tableTree/layui/layui.js"></script>
      <style>
        .grid-content {
          height: auto;
        }
      </style>
    </head>

    <body style="margin:20px !important">
      <!--主体内容层-->
      <div class="layui-row layui-col-space15" style="background:#fff;">
        <div class="layui-col-md12 layui-col-space15" style="padding:20px;">
          <div class="layui-btn-group demoTable" style="display:flex;justify-content:end;margin-bottom:20px;">
            <button class="layui-btn layui-btn-sm" onclick="addDepartment()" data-type="addEnterprise">
              <i class="layui-icon">&#xe654;</i>
            </button>
          </div>
          <%--tableTree生成位置--%>
            <div id="materialsTree"></div>
        </div>
      </div>
      <script id="view" type="text/html">
        <table class="layui-table">
          <thead>
            <tr>
              <th>名称</th>
              <th>创建时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            {{# layui.each(d.rows,function(index,r){ }}
            <tr>
              <td>{{r.name}}</td>
              <td>{{r.create_time}}</td>
              <!--操作按钮-->
              <td class="text-center">
                {{# if(r.isButton !=0) { }}
                <a class="layui-btn layui-btn-small layui-btn-warm" href="javascript:fn.view('{{r.id}}')">
                  <i></i>
                  查看
                </a>
                <a class="layui-btn layui-btn-small layui-btn-normal" href="javascript:fn.update('{{r.id}}')">
                  <i></i>
                  编辑
                </a>
                <a class="layui-btn layui-btn-small layui-btn-danger" href="javascript:fn.delete('{{r.id}}')">
                  <i></i>
                  删除
                </a>
                {{# } }}
              </td>
            </tr>
            {{# }); }}
          </tbody>
        </table>
      </script>
    </body>
    <script>

      layui.config({
        base: '${ctx}/common/plugins/tableTree/extend/'
      }).use(['laytpl', 'treegrid'], function () {
        var laytpl = layui.laytpl,
          treegrid = layui.treegrid;
        treegrid.config.render = function (viewid, data) {
          var view = document.getElementById(viewid).innerHTML;
          return laytpl(view).render(data) || '';
        };
        var rows = ${ json };
        var tree1 = treegrid.createNew({
          elem: 'materialsTree',
          view: 'view',
          data: { rows: rows },//在这里赋值
          parentid: 'pid',
          singleSelect: true
        });
        tree1.build();
      });
      var fn = {
        view: function (id) {
          window.location.href = '${ctx}/ddDetail/ddDetailViewPage?ddDetailId=' + id
        },
        update: function (id) {
          window.location.href = '${ctx}/ddDetail/ddDetailEditPage?ddDetailId=' + id + "&classify=${classify}"
        },
        delete: function (id) {
          layer.alert("确认删除?", "确认", function () {
            $.post("${ctx}/ddDetail/deleteRecursiveDdDetail", { id: id }, function (data) {
              if (data > 0) {
                layer.alert("删除成功");
                window.setTimeout(function () { window.location.reload() }, 2000)
              } else {
                layer.alert("删除失败");
              }
            }, "text")
          })
        }
      }
      function addDepartment() {
        window.location.href = '${ctx}/ddDetail/ddDetailEditPage?classify=${classify}&add=1'
      }
    </script>


    </html>